﻿Imports System.Data.SqlClient

Public Class Khabir
    Public Id As Integer
    Public Nom As String
    Public Prenom As String
    Public Ville As String
    Public Adress As String
    Public Remarque As String


    'Les constructeur ----------------------
    Sub New(ByVal Id As Integer, ByVal Nom As String, ByVal Prenom As String, ByVal Ville As String, ByVal Adress As String, ByVal Remarque As String)
        Me.Id = Id
        Me.Nom = Nom
        Me.Prenom = Prenom
        Me.Ville = Ville
        Me.Adress = Adress
        Me.Remarque = Remarque

    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Nom = enregistrement.Item(1)
        Me.Prenom = enregistrement.Item(2)
        Me.Ville = enregistrement.Item(3)
        Me.Adress = enregistrement.Item(4)
        Me.Remarque = enregistrement.Item(5)
    End Sub

    Sub New()

    End Sub

    'les listes ------------------------------

    Public list_phone As New ArrayList


    'les fonctions ------------------------

    Public Sub remplir_List_list_phone()
        Partager.close()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where id_Khabir =" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)

        Next
        Partager.Close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where Type ='" & type & "' and id_Khabir=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Khabir) values (@Num,@Type,@Id_Khabir)", Partager.con)

        cmd.Parameters.Add("@Id_Khabir", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        'Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_fichier_origine(ByVal idd As Integer, ByVal ph As fichier_origin)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub

End Class
